{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们使用Sequential容器组织一元线性回归模型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "vscode": {
     "languageId": "plaintext"
    }
   },
   "outputs": [],
   "source": [
    "import torch  \n",
    "import torch.nn as nn  \n",
    "  \n",
    "# 定义模型  \n",
    "model = nn.Sequential(  \n",
    "    nn.Linear(1, 1)  # 一个输入特征，一个输出特征  \n",
    ")  \n",
    "  \n",
    "# 定义损失函数  \n",
    "criterion = nn.MSELoss()  \n",
    "  \n",
    "# 假设有一些数据  \n",
    "inputs = torch.tensor([[1.0], [2.0], [3.0]])  \n",
    "targets = torch.tensor([[2.0], [4.0], [6.0]])  \n",
    "  \n",
    "# 前向传播  \n",
    "outputs = model(inputs)  \n",
    "  \n",
    "# 计算损失  \n",
    "loss = criterion(outputs, targets)  \n",
    "  \n",
    "print(loss)"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
